package com.skit.jetpackstudy.databinding;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

/**
 * Author: shuike,
 * Email: shuike007@126.com,
 * Date: 2019/12/29.
 * PS:
 */
public class MyViewModel extends ViewModel {
    private MutableLiveData<Integer> number;

    public MutableLiveData<Integer> getNumber() {
        if (number == null) {
            number = new MutableLiveData<>();
            number.setValue(0);
        }
        return number;
    }

    public void addNumber(int n) {
        if (number == null) return;
        number.setValue(n + (getNumber().getValue() == null ? 0 : getNumber().getValue()));
    }
}
